package com.bayi.program

import android.content.BroadcastReceiver
import android.content.Context
import android.content.Intent
import android.util.Log
import java.util.*


/**
 * @author Administrator on 2025-01-08.
 *
 *
 * 站在顶峰 看世界
 * 落到谷底 思人生
 */
class TimeChangeReceiver : BroadcastReceiver() {
    override fun onReceive(context: Context, intent: Intent) {
        val action = intent.action
        if (action != null && action == Intent.ACTION_TIME_TICK) {
            val mCalendar = Calendar.getInstance()
            val hour = mCalendar[Calendar.HOUR_OF_DAY]
            val minute = mCalendar[Calendar.MINUTE]
            Log.i("TimeChangeReceiver", "$hour:$minute")
            if (hour == 0 && minute == 10) {
                Thread {
                    val commandResult = ShellUtils.execCommand(arrayOf("su", "0", "reboot"), true)
                }
                    .start()
            } else if (hour == 6 && minute == 10) {
                Thread {
                    val commandResult = ShellUtils.execCommand(arrayOf("su", "0", "reboot"), true)
                }
                    .start()
            } else if (hour == 7 && minute == 10) {
                Thread {
                    val commandResult = ShellUtils.execCommand(arrayOf("su", "0", "reboot"), true)
                }.start()
            }

            // 构造广播 Intent
            val sendIntent = Intent("com.example.ACTION_CUSTOM")
            sendIntent.putExtra("data", "来自发送方的数据")
            sendIntent.setPackage(ProgramListeningSingle.PACKAGE_NAME)
            context.sendBroadcast(sendIntent)
        }
    }
}